package jp.co.hcs.attendancemanagement.data.dao.impl;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import jp.co.hcs.attendancemanagement.AMConstants;
import jp.co.hcs.attendancemanagement.data.dao.RestTimeActualDAO;
import jp.co.hcs.attendancemanagement.data.entity.RestTimeActual;
import jp.co.hcs.attendancemanagement.data.entity.Work;
import jp.co.hcs.attendancemanagement.data.entity.ex.RestTimeActualExample;
import jp.co.hcs.attendancemanagement.util.DateUtil;

public class RestTimeActualDAOImpl extends BaseDAOImpl implements RestTimeActualDAO {

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table tb5_kyuka_jisseki
     *
     * @ibatorgenerated Wed Mar 07 22:22:23 GMT+07:00 2012
     */
    public RestTimeActualDAOImpl() {
        super();
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table tb5_kyuka_jisseki
     *
     * @ibatorgenerated Wed Mar 07 22:22:23 GMT+07:00 2012
     */
    public int countRestTimeActualByExample(RestTimeActualExample example) throws SQLException {
        Integer count = (Integer)  sqlMapClient.queryForObject("tb5_kyuka_jisseki.ibatorgenerated_countByExample", example);
        return count;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table tb5_kyuka_jisseki
     *
     * @ibatorgenerated Wed Mar 07 22:22:23 GMT+07:00 2012
     */
    public int deleteRestTimeActualByExample(RestTimeActualExample example) throws SQLException {
        int rows = sqlMapClient.delete("tb5_kyuka_jisseki.ibatorgenerated_deleteByExample", example);
        return rows;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table tb5_kyuka_jisseki
     *
     * @ibatorgenerated Wed Mar 07 22:22:23 GMT+07:00 2012
     */
    public int deleteRestTimeActualByPrimaryKey(String restTakingId) throws SQLException {
        RestTimeActual key = new RestTimeActual();
        key.setRestTakingId(restTakingId);
        int rows = sqlMapClient.delete("tb5_kyuka_jisseki.ibatorgenerated_deleteByPrimaryKey", key);
        return rows;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table tb5_kyuka_jisseki
     *
     * @ibatorgenerated Wed Mar 07 22:22:23 GMT+07:00 2012
     */
    public void insertRestTimeActual(RestTimeActual record) throws SQLException {
        sqlMapClient.insert("tb5_kyuka_jisseki.ibatorgenerated_insert", record);
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table tb5_kyuka_jisseki
     *
     * @ibatorgenerated Wed Mar 07 22:22:23 GMT+07:00 2012
     */
    public void insertRestTimeActualSelective(RestTimeActual record) throws SQLException {
        sqlMapClient.insert("tb5_kyuka_jisseki.ibatorgenerated_insertSelective", record);
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table tb5_kyuka_jisseki
     *
     * @ibatorgenerated Wed Mar 07 22:22:23 GMT+07:00 2012
     */
    @SuppressWarnings("unchecked")
    public List<RestTimeActual> selectRestTimeActualByExample(RestTimeActualExample example) throws SQLException {
        List<RestTimeActual> list = sqlMapClient.queryForList("tb5_kyuka_jisseki.ibatorgenerated_selectByExample", example);
        return list;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table tb5_kyuka_jisseki
     *
     * @ibatorgenerated Wed Mar 07 22:22:23 GMT+07:00 2012
     */
    public RestTimeActual selectRestTimeActualByPrimaryKey(String restTakingId) throws SQLException {
        RestTimeActual key = new RestTimeActual();
        key.setRestTakingId(restTakingId);
        RestTimeActual record = (RestTimeActual) sqlMapClient.queryForObject("tb5_kyuka_jisseki.ibatorgenerated_selectByPrimaryKey", key);
        return record;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table tb5_kyuka_jisseki
     *
     * @ibatorgenerated Wed Mar 07 22:22:23 GMT+07:00 2012
     */
    public int updateRestTimeActualByExampleSelective(RestTimeActual record, RestTimeActualExample example) throws SQLException {
        UpdateByExampleParms parms = new UpdateByExampleParms(record, example);
        int rows = sqlMapClient.update("tb5_kyuka_jisseki.ibatorgenerated_updateByExampleSelective", parms);
        return rows;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table tb5_kyuka_jisseki
     *
     * @ibatorgenerated Wed Mar 07 22:22:23 GMT+07:00 2012
     */
    public int updateRestTimeActualByExample(RestTimeActual record, RestTimeActualExample example) throws SQLException {
        UpdateByExampleParms parms = new UpdateByExampleParms(record, example);
        int rows = sqlMapClient.update("tb5_kyuka_jisseki.ibatorgenerated_updateByExample", parms);
        return rows;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table tb5_kyuka_jisseki
     *
     * @ibatorgenerated Wed Mar 07 22:22:23 GMT+07:00 2012
     */
    public int updateRestTimeActualByPrimaryKeySelective(RestTimeActual record) throws SQLException {
        int rows = sqlMapClient.update("tb5_kyuka_jisseki.ibatorgenerated_updateByPrimaryKeySelective", record);
        return rows;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table tb5_kyuka_jisseki
     *
     * @ibatorgenerated Wed Mar 07 22:22:23 GMT+07:00 2012
     */
    public int updateRestTimeActualByPrimaryKey(RestTimeActual record) throws SQLException {
        int rows = sqlMapClient.update("tb5_kyuka_jisseki.ibatorgenerated_updateByPrimaryKey", record);
        return rows;
    }
    
	public List<RestTimeActual> getValidRestTimeActualList(String employeeId, Date startOfYear)
			throws SQLException {
		RestTimeActualExample example = new RestTimeActualExample();
		List<String> jobTypes = new ArrayList<String>();
		jobTypes.add(AMConstants.PAID_LEAVE);
		jobTypes.add(AMConstants.HALF_MORNING_LEAVE);
		jobTypes.add(AMConstants.HALF_AFTERNOON_LEAVE);
		jobTypes.add(AMConstants.TIME_PAID_LEAVE);
		example.createCriteria().andEmployeeIdEqualTo(employeeId)
				.andRestTypeIn(jobTypes)
				.andRestTakingStartDateGreaterThanOrEqualTo(startOfYear)
				.andRestTakingEndDateLessThanOrEqualTo(DateUtil.getEndOfYear(startOfYear));
		return selectRestTimeActualByExample(example);
	}
	
	@SuppressWarnings("unchecked")
	public List<String> getRestTimeActualSeqNum(String employeeId, String date) throws SQLException {
		String combinationKey = employeeId + date;
		List<String> list = sqlMapClient.queryForList("tb5_kyuka_jisseki.getSequenceNumber", combinationKey);
		return list;
	}

    /**
     * This class was generated by Apache iBATIS ibator.
     * This class corresponds to the database table tb5_kyuka_jisseki
     *
     * @ibatorgenerated Wed Mar 07 22:22:23 GMT+07:00 2012
     */
    private static class UpdateByExampleParms extends RestTimeActualExample {
        private Object record;

        public UpdateByExampleParms(Object record, RestTimeActualExample example) {
            super(example);
            this.record = record;
        }

        public Object getRecord() {
            return record;
        }
    }

}